// TypeScript file
class PostLink extends egret.Sprite{
    public UP_LOAD:string = "upload";
    public LOAD_ERROR:string = "loaderror";
    public constructor (){
        super();
    }
    /************后台数据交互 */
    // public urlJson;
     public upload(urlStr:string,urldata:egret.URLVariables): void {
       //console.log("发送数据到后台");
       var variables = urldata;
       var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(urlStr);
        req.method = egret.URLRequestMethod.POST;
        req.data = variables;
        urlloader.load(req);
        var self = this;
        urlloader.once(egret.Event.COMPLETE, (e) => {
           // egret.log("后台返回"+e.target.data);
            var jsObj = JSON.parse(e.target.data);
            if (jsObj) {
                self.dispatchEventWith(self.UP_LOAD,false,jsObj);
            }
        }, this);
        urlloader.once(egret.IOErrorEvent.IO_ERROR,(e) => {            
                self.dispatchEventWith(self.LOAD_ERROR); 
        }, this);
    } 
    /******************************************************** */
}